using UnityEngine;
using System.Collections;

public class Singleton<T> where T : Singleton<T>, new() {
    private static T _instance = null;
    private static bool _intialized = false;
    public static T Instance {
        get {
            if ( _instance == null && _intialized == false ) {
                _instance = new T();
                _intialized = true;
            }
            return _instance;
        }
    }

    public static T Create() {
        if ( !_intialized ) {
            T ret = Instance;
            ret.Initialize();
            return ret;
        }
        return _instance;
    }

    public static void Destroy() {
        if ( _intialized && _instance != null ) {
            _instance.Uninitialize();
            _instance = null;
            _intialized = false;
        }
    }

    public virtual void Initialize() { }

    public virtual void Uninitialize() { }

}